package com.suixinsanren.design.state.demo.demo07;

public class HashQuarterState implements State {

    private final GumballMachine gumballMachine;

    public HashQuarterState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    @Override
    public void insertQuarter() {
        System.out.println("已经投过币了，请开始游戏");
    }

    @Override
    public void ejectQuarter() {
        gumballMachine.setState(gumballMachine.getNoQuarterState());
        System.out.println("您的硬币已退还");
    }

    @Override
    public void turnCrank() {
        System.out.println("您转动了曲柄，游戏开始");
        if (gumballMachine.getNumberGumball() > 0) {
            gumballMachine.setState(gumballMachine.getSoldState());
        } else {
            System.out.println("糖果已售罄");
            gumballMachine.setState(gumballMachine.getSoldOutState());
        }
    }

    @Override
    public String toString() {
        return "已投币状态";
    }
}
